#include "TK.h"
#include <stdbool.h>

bool circle(Node *head){
	if(head == NULL || head->next == NULL)
	return false;
	Node *slow = head->next;
	Node *fast = head->next->next;
	while(fast)//"even node" flag
	{
		if(fast == slow)
		return true;
		slow = slow->next;
		if(fast->next)//"odd node" flag
		fast = fast->next->next;
		else
		return false;
	}
	return false;
}

int main(int argc,char *argv[]){
	Node *head = (Node *)malloc(sizeof(Node));//be caution!
	head->next = NULL;// do not define "head = NULL",because you cannot "NULL->next =" or "NULL->data =".
	Node *pend = head;
	int i = 1;
	while(i<argc)
	{
		Node *pnew = (Node *)malloc(sizeof(Node));
		pnew->data = *argv[i++];
		pnew->next = NULL;//add final node.
		pend->next = pnew;
		pend = pnew;	
	}
	//pend->next = head->next;//if only one node.this operation will disturb the function "circle",because the sole node "X" ,its X->next = X rather than X->next = NULL so that the function "circle" cannot return false. 
	if(argc>2)
	pend->next = head->next;//printf circle exists! you can try to erase code.
	head = head->next;
	if(circle(head))
	printf("circle exists!\n");
	else
	printf("no circle!\n");
} 
